<?php

class Product extends Eloquent {
	 protected $table = 'product';

	/**
	 * Condition: Unarchived Items.
	 * @author AngelaMisa 02/22/2015 2:25AM
	 * @param $query
	 * @return mixed
	 */
	public function scopeActive( $query ) {
		return $query->where($this->table . '.archived', 0);
	}
	
	/**
	 * Relates to Product Size.
	 * @author AngelaMisa 02/25/2015 5:21PM
	 * @return mixed
	 */
	public function size() {
		return $this->belongsTo('Size', 'SIZE_id');
	}
	
	/**
	 * Retrieves Orders that includes Product.
	 * @author AngelaMisa 02/23/2015 9:51PM
	 * @return mixed
	 */
	public function orders() {
		return $this->belongsToMany('Order', 'order_product', 'PRODUCT_id', 'ORDER_id');
	}
	
	/**
	 * Retrieves Vendors under Product.
	 * Usage: Product::find(3)->vendors, Product::has('vendors')
	 * @author AngelaMisa 02/23/2015 9:51PM
	 * @return mixed
	 */
	public function vendors() {
		return $this->belongsToMany('Vendor', 'product_vendor', 'PRODUCT_id', 'VENDOR_id');
	}
}